package com.woniuxy.microutilsserver.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author unreleased
 * @date 2021/1/29 18:08
 * 发送短信工具类
 */
@Component
public class MsgUtil {

    private static String keyId;

    private static String secret;
    @Value("${aliyunms.access-key}")
    public void setKeyId(String keyId) {
        MsgUtil.keyId = keyId;
    }

    @Value("${aliyunms.secret}")
    public void setSecert(String secret) {
        MsgUtil.secret = secret;
    }

    private MsgUtil() {
    }

    public static void sendMsg(String tel, String deliveryId) {
        System.out.println("发送信息");
        System.out.println("tel = " + tel + ", deliveryId = " + deliveryId);
//        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", keyId, secret);
//        IAcsClient client = new DefaultAcsClient(profile);
//        //构建请求
//        CommonRequest request = new CommonRequest();
//        //下面的信息不要改
//        request.setSysMethod(MethodType.POST);
//        request.setSysDomain("dysmsapi.aliyuncs.com");
//        request.setSysVersion("2017-05-25");
//        request.setSysAction("SendSms");
//        //自定义的参数（手机号、签名和模版CODE）
//        request.putQueryParameter("PhoneNumbers", tel);
//        request.putQueryParameter("SignName", "蜗牛");
//        request.putQueryParameter("TemplateCode", "SMS_204116118");
//        //构建一个短信验证码
//        HashMap<String, Object> map = new HashMap<>();
//        map.put("code", deliveryId);
//        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));
//        //尝试发送
//        try {
//            CommonResponse response = client.getCommonResponse(request);
//            System.out.println(response.getData());
//        } catch (ClientException e) {
//            e.printStackTrace();
//        }
    }

}
